package com.benyi.util;

import com.fasterxml.jackson.annotation.JsonInclude;
 



@JsonInclude(JsonInclude.Include.ALWAYS)
public class JsonResult<T> {
	public static final int SUCCESS = 1;
	public static final int FAIL = 0;
	
	private int status;
	private String errCode;
	private String desc;
	private T data;
	
	public JsonResult(){
		//
	}
	 
	public String getErrCode() {
		return errCode;
	} 

	public void setErrCode(String errCode) {
		this.errCode = errCode;
	} 

	public static <T> JsonResult<T> success(){
		JsonResult<T> e=new JsonResult<T>();
		e.status = SUCCESS;
		return e;
	}
	
	public static <T> JsonResult<T> fail(){
		JsonResult<T> e=new JsonResult<T>();
		e.status = FAIL;
		e.data=null;
		return e;
	}
	
	public static <T> JsonResult<T> success(String msg){
		JsonResult<T> e=new JsonResult<T>();
		e.status = SUCCESS;
		e.desc = msg;  
		return e;
	}
	
	public static <T> JsonResult<T> fail(String msg){
		JsonResult<T> e=new JsonResult<T>();
		e.status = FAIL;
		e.desc=msg;
		e.data=null;
		return e;
	}
	
	public static <T> JsonResult<T> fail(String ecode, String msg){
		JsonResult<T> e=new JsonResult<T>();
		e.status = FAIL;
		e.desc=msg;
		e.data=null;
		e.errCode = ecode;
		return e;
	}
	 
	
	public static <T> JsonResult<T> success(T v,String msg){
		JsonResult<T> e=new JsonResult<T>();
		e.status = SUCCESS;
		e.desc=msg;
		e.setData(v);
		return e;
	}
	
	public void setStatus(int status){
		this.status=status;
	}
	
	public int getStatus(){
		return status;
	}
	
	public void setDesc(String desc){
		this.desc=desc;
	}
	
	public String getDesc(){
		return desc;
	}
	
	public void setData(T v){
		data=v;
	}
	
	public T getData(){
		return data;
	}  
	 
}
